package utro;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * User: Iaroslav.Zavoiura
 * Date: 11/15/13
 * Time: 11:29 AM
 * To change this template use File | Settings | File Templates.
 */
public class utro {
    public WebDriver driver;
    @Test
    public void Astes1 () throws InterruptedException {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://buxfer.com");
        TimeUnit.SECONDS.sleep(5);
        driver.findElement(By.xpath(".//*[@id='login_form']/div[1]/table/tbody/tr/td[3]/table/tbody/tr[2]/td/div/a")).click();
        TimeUnit.SECONDS.sleep(2);
        driver.findElement(By.xpath(".//*[@id='__pageBody']/div[2]/div[3]/div/div[2]/a")).click();
        TimeUnit.SECONDS.sleep(2);
        driver.findElement(By.id("signupEmail")).click();
        driver.findElement(By.id("signupEmail")).sendKeys("yarik.zavik54@yandex.ru");
        TimeUnit.SECONDS.sleep(2);
        driver.findElement(By.id("signup_password")).click();
        driver.findElement(By.id("signup_password")).sendKeys("yarik.zavik");
        TimeUnit.SECONDS.sleep(2);
        driver.findElement(By.xpath(".//*[@id='signup_table']/tbody/tr[5]/td[2]/div[1]/table/tbody/tr[2]/td/div")).click();
        TimeUnit.SECONDS.sleep(5);
        driver.findElement(By.xpath(".//*[@id='overlay']/table/tbody/tr[3]/td/div[1]/div/img")).click();
        TimeUnit.SECONDS.sleep(4);
        String text=driver.findElement(By.xpath(".//*[@id='__pageBody']/div[1]/div/div/div[2]/div[3]/div/div[7]/a")).getText();
        Assert.assertEquals(text,"Upgrade");
        Assert.assertEquals(driver.getCurrentUrl(),"https://www.buxfer.com/home#/home");
        TimeUnit.SECONDS.sleep(4);
        driver.findElement(By.cssSelector(".drpdwnHandler")).click();
        TimeUnit.SECONDS.sleep(4);
        driver.findElement(By.xpath("//div[contains(text(),'Profile')]")).click();
        TimeUnit.SECONDS.sleep(4);
        driver.findElement(By.xpath(".//a[text() = 'Delete account']")).click();
        TimeUnit.SECONDS.sleep(4);
        driver.findElement(By.xpath(".//a [text() = 'Yes, delete my account']")).click();
        TimeUnit.SECONDS.sleep(4);
        driver.findElement(By.cssSelector(".ttMargin>input")).click();
        driver.findElement(By.cssSelector(".ttMargin>input")).sendKeys("yarik.zavik");
        TimeUnit.SECONDS.sleep(4);
        driver.findElement(By.cssSelector(".ttMargin>textarea")).click();
        driver.findElement(By.cssSelector(".ttMargin>textarea")).sendKeys("yarik.zavik");
        TimeUnit.SECONDS.sleep(4);
        driver.findElement(By.xpath(".//a[text()='Delete my account']")).click();
        TimeUnit.SECONDS.sleep(4);
        Assert.assertEquals(driver.getCurrentUrl(),"https://www.buxfer.com/");
       // if (text.equals("Upgrade"))
       // {
       //     System.out.println("Я залогинился");
       // }
       // else
       // {
       //     System.out.println("Тест не прошел");
      //  }
        //driver.findElement(By.cssSelector(".drpdwnHandler")).click();
        //TimeUnit.SECONDS.sleep(4);
        //driver.findElement(By.className("opt/[12]")).click();
        //TimeUnit.SECONDS.sleep(10);
        driver.quit();
    }

    @Test
    public void Astes2 () throws InterruptedException {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://buxfer.com");
        TimeUnit.SECONDS.sleep(5);
        driver.findElement(By.id("login_username")).click();
        driver.findElement(By.id("login_username")).sendKeys("yarik.zavik24@yandex.ru");
        TimeUnit.SECONDS.sleep(5);
        driver.findElement(By.id("login_username")).click();
        driver.findElement(By.id("login_password")).sendKeys("yarik.zavik");
        TimeUnit.SECONDS.sleep(5);
        driver.findElement(By.xpath(".//*[@id='login_form']/div[1]/table/tbody/tr/td[3]/table/tbody/tr[2]/td/div/a")).click();
        TimeUnit.SECONDS.sleep(5);
        driver.findElement(By.xpath(".//*[@id='overlay']/table/tbody/tr[3]/td/div[1]/div/img")).click();
        TimeUnit.SECONDS.sleep(4);
        String text=driver.findElement(By.xpath(".//*[@id='__pageBody']/div[1]/div/div/div[2]/div[3]/div/div[7]/a")).getText();
        Assert.assertEquals(text,"Upgrade");
        // if (text.equals("Upgrade"))
        // {
        //    System.out.println("Я залогинился");
        // }
        // else
        // {
        //    System.out.println("Тест не прошел");
        //}
        driver.findElement(By.cssSelector(".drpdwnHandler")).click();
        driver.findElement(By.xpath("//div[contains(text(),'Logout')]")).click();
        TimeUnit.SECONDS.sleep(4);
        Assert.assertEquals(driver.getCurrentUrl(),"https://www.buxfer.com/");
        driver.quit();

}
    @Test
    public void Astes3 () throws InterruptedException {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://buxfer.com");
        TimeUnit.SECONDS.sleep(5);
        driver.findElement(By.id("login_username")).click();
        driver.findElement(By.id("login_username")).sendKeys("ерикеиркиркu");
        TimeUnit.SECONDS.sleep(5);
        driver.findElement(By.id("login_username")).click();
        driver.findElement(By.id("login_password")).sendKeys("киркеиекир");
        TimeUnit.SECONDS.sleep(5);
        driver.findElement(By.xpath(".//*[@id='login_form']/div[1]/table/tbody/tr/td[3]/table/tbody/tr[2]/td/div/a")).click();
        TimeUnit.SECONDS.sleep(5);
        String text=driver.findElement(By.id("login_errordiv")).getText();
        Assert.assertEquals(text,"Invalid username or email");
        // if (text.equals("Invalid username or email"))
        // {
        //    System.out.println("Я не залогинился под фейком");
        // }
        // else
        // {
        //    System.out.println("Тест не прошел");
        // }
        driver.quit();

    }

    @AfterSuite
    public void Clean(){
        if(driver!=null)
            driver.quit();
    }
}